import { request } from '@/utils/request'
import type { UserType, CodeType, UserInfoType, PatientList, Patient } from '@/types/user'
/**
 * 短信登录
 * @param mobile 手机号
 * @param password 密码
 */
export const loginApi = (mobile: string, password: string) => {
  return request<UserType>('login/password', 'POST', {
    mobile,
    password
  })
}

/**
 * 获取验证码
 * @param mobile 手机号
 * @param type 验证码类型
 */
export const codeApi = (mobile: string, type: CodeType) => {
  return request('code', 'get', {
    mobile,
    type
  })
}

/**
 * 验证码登录
 * @param mobile 手机号
 * @param code 验证码
 */
export const codeBtnApi = (mobile: string, code: string) => {
  return request<UserType>('login', 'POST', {
    mobile,
    code
  })
}
/**
 * 获取用户信息
 */
export const userInfoApi = () => {
  return request<UserInfoType>('patient/myUser', 'get')
}
/**
 * 获取患者列表信息
 */
export const patientListApi = () => {
  return request<PatientList>('patient/mylist', 'get')
}
/**
 * 添加患者
 验证码
 */
export const addPatientApi = (patient: Patient) => {
  return request<UserType>('patient/add', 'POST', patient)
}
/**
 * 编辑患者
 验证码
 */
export const editPatientApi = (patient: Patient) => {
  return request<UserType>('patient/update', 'put', patient)
}
/**
 *删除患者
 验证码
 */
export const delPatientApi = (id: string) => {
  return request<UserType>(`patient/del/${id}`, 'delete')
}
/**
 * 查询患者详情
 */
export const getPatientDetail = (id: string) => request<Patient>(`patient/info/${id}`)
/**
 * 未读消息
 */
export const getUnreadMsgApi = () => request<number>(`patient/message/unRead/all`)

/**
 * qq三方登录
 */
export const loginByQQ = (openId: string) =>
  request<UserType>('login/thirdparty', 'POST', { openId, source: 'qq' })

/**
 * qq三方登录 绑定手机号
 */
export const bindMobile = (data: { mobile: string; code: string; openId: string }) =>
  request<UserType>('login/binding', 'POST', data)
